package com.cloudwise.gproject.service.impl;

import com.cloudwise.gproject.entity.Progress;
import com.cloudwise.gproject.dao.ProgressDao;
import com.cloudwise.gproject.service.ProgressService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * (Progress)表服务实现类
 *
 * @author makejava
 * @since 2021-03-24 09:19:30
 */
@Service("progressService")
public class ProgressServiceImpl implements ProgressService {
    @Resource
    private ProgressDao progressDao;

    /**
     * 通过ID查询单条数据
     *
     * @param progressId 主键
     * @return 实例对象
     */
    @Override
    public Progress queryById(Integer progressId) {
        return this.progressDao.queryById(progressId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Progress> queryAllByLimit(int offset, int limit) {
        return this.progressDao.queryAllByLimit(offset, limit);
    }

    @Override
    public PageInfo queryAll(Integer page, Integer limit, Progress progress) {
        //设值查询查询
        PageHelper.startPage(page,limit);
        PageInfo PageInfo = new PageInfo(progressDao.queryAll(progress));
        return PageInfo;
    }

    /**
     * 新增数据
     *
     * @param progress 实例对象
     * @return 实例对象
     */
    @Override
    public Progress insert(Progress progress) {
        this.progressDao.insert(progress);
        return progress;
    }

    /**
     * 修改数据
     *
     * @param progress 实例对象
     * @return 实例对象
     */
    @Override
    public Progress update(Progress progress) {
        this.progressDao.update(progress);
        return this.queryById(progress.getProgressId());
    }

    /**
     * 通过主键删除数据
     *
     * @param progressId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer progressId) {
        return this.progressDao.deleteById(progressId) > 0;
    }

    @Override
    public int deleteIds(String deleteIds) {
        return 0;
    }

    /** 
     * @create by: 卫子健
     * @description: 按照时间为横坐标展示进度 
     * @create time: 2021/3/25 16:53
     * @param loginName
     * @param progressType 
     * @return com.cloudwise.trademark.util.Result 
     */
    @Override
    public Map<String, Object> progressEchartTime(String loginName, String progressType) {
        List<Map<String, Object>> maps = progressDao.progressEchartTime(loginName, progressType);
        Map<String, Object> map = new HashMap<>();
        //定义x轴
        String[] monthX = new String[maps.size()];
        //定义y轴
        Integer[] progressCountY = new Integer[maps.size()];
        for (int i = 0; i < maps.size(); i++) {
            monthX[i] = maps.get(i).get("month").toString();
            progressCountY[i] = Integer.parseInt(maps.get(i).get("progressCount").toString());
        }
        map.put("monthX", monthX);
        map.put("progressCountY", progressCountY);
        return map;
    }

    /** 
     * @create by: 卫子健
     * @description: 按照名字为横坐标展示进度 
     * @create time: 2021/3/25 17:49
     * @param startTime
     * @param endTime
     * @param progressType 
     * @return java.util.Map<java.lang.String,java.lang.Object> 
     */
    @Override
    public Map<String, Object> progressEchartName(String startTime, String endTime, String progressType) {
        List<Map<String, Object>> maps = progressDao.progressEchartName(startTime, endTime, progressType);
        Map<String, Object> map = new HashMap<>();
        //定义x轴
        String[] proxyX = new String[maps.size()];
        //定义y轴
        Integer[] progressCountY = new Integer[maps.size()];
        for (int i = 0; i < maps.size(); i++) {
            proxyX[i] = maps.get(i).get("proxyName").toString();
            progressCountY[i] = Integer.parseInt(maps.get(i).get("count").toString());
        }
        map.put("proxyX", proxyX);
        map.put("progressCountY", progressCountY);
        return map;
    }


}
